The table of contents appears in the Right Sidebar automatically when there are multiple headings in a text note.
In Text Notes options, look for the Table of Contents section and configure the minimum amount of headings that need to be present in the current note in order for the table of contents to show:
Use Attributes to configure the table of contents for a particular note:
#toc=show will show the table of contents for that note regardless
of the global settings.#toc=hide will always hide the table of contents
for that note.